﻿using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestDLR : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- DLR (Dynamic language runtime) ---");
        }

        public void doTest()
        {
            ScriptEngine engine = Python.CreateEngine();
            ScriptScope scope = engine.CreateScope();
            scope.SetVariable("ContactName", "TestPythonMan");
            scope.SetVariable("ContactPhone", "010-python-0000");
            ScriptSource scriptSrc = engine.CreateScriptSourceFromString(
@"
class PythonContact :
    name = ''
    phone = ''

    def __init__(self, name, phone) :
        self.name = name
        self.phone = phone

    def printContact(self) :
        print self.name + ', ' + self.phone

PythonContact(ContactName, ContactPhone)
");
            dynamic pythonContactObj = scriptSrc.Execute(scope);
            pythonContactObj.printContact();
        }
    }
}
